<?php

/**
 * 竞拍
 *
 * Created by PhpStorm.
 * User: evan
 * Date: 16/9/6
 * Time: 下午11:23
 */
class Bidding extends MY_Api_Controller
{
    /**
     * 竞拍
     */
    public function index()
    {
        $aid = (int)$this->input->get_post('aid');


        $this->load->service('auction/service_auction_bidding');
        $data = $this->service_auction_bidding->index($aid, $this->uid);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 最新出价记录
     */
    public function newest()
    {
        $aid   = (int)$this->input->get_post('aid');
        $page  = (int)$this->input->get_post('page');
        $limit = (int)$this->input->get_post('limit');


        $this->load->service('auction/service_auction_bidding');
        $data = $this->service_auction_bidding->newest($aid, $page, $limit);


        $this->json_output($data['data'], $data['status']);
    }
    
    
    /**
     * 当前竞拍最高价
     */
    public function highest_offer()
    {
    	$aid   = (int)$this->input->get_post('aid');
    
    	$this->load->service('auction/service_auction_bidding');
    	$data = $this->service_auction_bidding->highest_offer($aid);
    
    	$this->json_output($data['data'], $data['status']);
    }


    /**
     * 加价
     */
    public function fare()
    {
        $aid    = (int)$this->input->get_post('aid');
        $uid    = $this->uid;
        $amount = (int)$this->input->get_post('amount');
        $pay_password     = trim($this->input->get_post('pay_password'));
        $is_save_password = (bool)$this->input->get_post('is_save_password');


        $this->load->service('auction/service_auction_bidding');
        $data = $this->service_auction_bidding->fare($aid, $uid, $amount, $pay_password, $is_save_password);


        $this->json_output($data['data'], $data['status']);
    }


    /**
     * 通过id获取某一条出价
     */
    public function by_id()
    {
        $aid = (int)$this->input->get_post('aid');
        $id  = (int)$this->input->get_post('id');


        $this->load->service('auction/service_auction_bidding');
        $data = $this->service_auction_bidding->by_id($aid, $id);


        $this->json_output($data['data'], $data['status']);
    }
}